package cn.snmp.mutual.org.opennms.protocols.snmp;

import java.io.*;

import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnDecodingException;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncoder;
import cn.snmp.mutual.org.opennms.protocols.snmp.asn1.AsnEncodingException;

public class SnmpInt32 implements SnmpSyntax, Cloneable, Serializable {
    private int m_value;
    static final long serialVersionUID = -3472172482048507843L;
    public static final byte ASNTYPE = 2;

    public SnmpInt32() {
        this.m_value = 0;
    }

    public SnmpInt32(final int value) {
        this.m_value = value;
    }

    public SnmpInt32(final Integer value) {
        this.m_value = value;
    }

    public SnmpInt32(final SnmpInt32 second) {
        this.m_value = second.m_value;
    }

    public int getValue() {
        return this.m_value;
    }

    public void setValue(final int value) {
        this.m_value = value;
    }

    public void setValue(final Integer value) {
        this.m_value = value;
    }

    public byte typeId() {
        return 2;
    }

    public int encodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnEncodingException {
        return encoder.buildInteger32(buf, offset, this.typeId(), this.m_value);
    }

    public int decodeASN(final byte[] buf, final int offset, final AsnEncoder encoder) throws AsnDecodingException {
        final Object[] rVals = encoder.parseInteger32(buf, offset);
        if ((byte) rVals[1] != this.typeId()) {
            throw new AsnDecodingException("Invalid ASN.1 type");
        }
        this.m_value = (int) rVals[2];
        return (int) rVals[0];
    }

    public SnmpSyntax duplicate() {
        return new SnmpInt32(this);
    }

    public Object clone() {
        return new SnmpInt32(this);
    }

    @Override
    public String toString() {
        return String.valueOf(this.getValue());
    }
}
